<template>
  <div>
    <GoodFrom @submit="handleSubmit" :formData="formData" />
  </div>
</template>

<script>
import GoodFrom from "./Components/GoodFrom.vue";
import {getGoodInfo} from "@/api/products.js";
import {editGoodInfo} from "@/api/products.js";
export default {
  components: {
    GoodFrom,
  },
  async created(){
    await this.handleEditData();    
  },
  data(){
    return {
      formData :''
    }
  },
  methods:{
    async handleSubmit(from){
      await editGoodInfo({
        ...from,
        images : from.images.map(it=>it.url)
      });
      this.$router.push({
        name : 'GoodList'
      })
    },
    async handleEditData(){
      let id = this.$route.params.id;
      let editData = await getGoodInfo({id});
      editData.images = editData.images.map((it,i)=>({url:it,id:i}))
      
      this.formData = editData
    },
  },
};
</script>

<style>
</style>